import 'package:flutter/material.dart';
import 'package:flutter_shop/pages/home/info/data.dart';

class Info extends StatelessWidget {
  final bool showTitle;
  final List<InfoItem> dataList;

  const Info({Key key, this.showTitle = false, this.dataList = infoData})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: [
          if (showTitle)
            Container(
              child: Text('最新资讯'),
              alignment: Alignment.topLeft,
              padding: EdgeInsets.symmetric(horizontal: 10),
            ),
          Column(
            children: dataList
                .map((item) => Container(
                      height: 100,
                      padding: EdgeInsets.only(left: 10, right: 10, bottom: 5),
                      child: Row(
                        children: [
                          Image.asset(
                            item.imageUrl,
                            width: 100,
                            height: 100,
                            fit: BoxFit.cover,
                          ),
                          Padding(padding: EdgeInsets.only(left: 10)),
                          Expanded(
                              child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(item.title),
                              Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Text(
                                    item.source,
                                    style: TextStyle(color: Colors.grey),
                                  ),
                                  Text(item.time,
                                      style: TextStyle(color: Colors.grey))
                                ],
                              )
                            ],
                          ))
                        ],
                      ),
                    ))
                .toList(),
          )
        ],
      ),
    );
  }
}
